package com.justcan.demo.cartoon.utils.anim;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Canvas;
import android.view.View;

/**
 * 负责绘制一组AnimObject
 * @author zhanghuijun
 *
 */
public class AnimObjectGroup extends AnimObject {

	/**
	 * 一组AnimObject
	 */
	protected List<AnimObject> mAnimObjects = null;

	public AnimObjectGroup(View mRootAnimView, Context mContext) {
		super(mRootAnimView, mContext);
		mAnimObjects = new ArrayList<AnimObject>();
	}

	/**
	 * 添加一个AnimObject
	 */
	public void addAnimObject(AnimObject object) {
		object.setParent(this);
		mAnimObjects.add(object);
	}

	/**
	 * 移除一个AnimObject
	 */
	public void removeAnimObject(AnimObject object) {
		mAnimObjects.remove(object);
	}


	@Override
	public void logic(long animTime, long deltaTime) {
		// 按顺序执行AnimObject的逻辑
		for (int i = 0; i < mAnimObjects.size(); i++) {
			mAnimObjects.get(i).logic(animTime, deltaTime);
		}
	}

	@Override
	public void draw(Canvas canvas, int sceneWidth, int sceneHeight) {
		// 按顺序绘制AnimObject
		for (int i = 0; i < mAnimObjects.size(); i++) {
			mAnimObjects.get(i).draw(canvas, sceneWidth, sceneHeight);
		}
	}

	@Override
	public void onSizeChange(int w, int h) {
		for (int i = 0; i < mAnimObjects.size(); i++) {
			mAnimObjects.get(i).onSizeChange(w, h);
		}
	}

	/**
	 * 获取子Object
	 */
	public List<AnimObject> getAnimObjects() {
		return mAnimObjects;
	}
}
